package com.cloud.hotline.api.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.hotline.api.bean.HotlineCalculateForm;
import com.cloud.hotline.api.service.HotlineStatService;
import com.cloud.hotline.common.result.Quokka;

@RestController
@RequestMapping("hotline/api/stat")
public class HotlineStatController {

	@Autowired
	private HotlineStatService hotlineStatService;

	@PostMapping("calculate")
	public Quokka calculate(@RequestBody HotlineCalculateForm form) {
		return new Quokka(true, hotlineStatService.calculate(form));
	}
	
	@PostMapping("detail")
	public Quokka detail(HttpServletRequest request, @RequestBody HotlineCalculateForm form){
		int pageNum = ServletRequestUtils.getIntParameter(request, "pageNum", 1);
		int pageSize = ServletRequestUtils.getIntParameter(request, "pageSize", 30);
		return new Quokka(true, hotlineStatService.detail(form, pageNum, pageSize));
	}
	
	
}
